package com.hzhc.controller.message;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hzhc.annotation.SysTemLog;
import com.hzhc.common.BaseController;
import com.hzhc.enumBean.ResultUtilCodeEnum;
import com.hzhc.service.SmsTemplateService;
import com.hzhc.utils.ResultUtil;
import com.hzhc.utils.TokenUtil;
import com.hzhc.vo.SmsTemplateVo;
import lombok.RequiredArgsConstructor;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author dongcy
 * @date 2024/6/17 10:37
 * @description SmsTemplateController
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/smsTemplate")
public class SmsTemplateController extends BaseController {

    private final SmsTemplateService templateService;

    /**
     * 短信模板 list列表
     * @param request
     * @param vo
     * @return
     */
    @RequestMapping("/getMessageTemplateList")
    public ResultUtil<List<SmsTemplateVo>> getMessageTemplateList(HttpServletRequest request, @RequestBody SmsTemplateVo vo){
        Page<SmsTemplateVo> page = new Page<>(vo.getPageIndex(),vo.getPageSize());
        List<SmsTemplateVo> list = templateService.getMessageTemplateList(page,vo);
        return ResultUtil.build(list,page.getTotal(),page.getPages(), ResultUtilCodeEnum.SUCCESS);
    }

    /**
     * 短信模板 新增
     * @param request
     * @param vo
     * @return
     */
    @RequestMapping("/addMessageTemplate")
    @SysTemLog(operModul = "短信模板-添加", operType = "ADD", operDesc = "短信模板添加功能", modular = "PC")
    public ResultUtil<T> addMessageTemplate(HttpServletRequest request, @RequestBody SmsTemplateVo vo){
        Long userID = TokenUtil.getUserID(request);
        vo.setUserId(userID);
        return templateService.addMessageTemplate(vo);
    }

    /**
     * 短信模板 修改
     * @param request
     * @param vo
     * @return
     */
    @RequestMapping("/updateMessageTemplate")
    @SysTemLog(operModul = "短信模板-修改", operType = "UPDATE", operDesc = "短信模板修改功能", modular = "PC")
    public ResultUtil<T> updateMessageTemplate(HttpServletRequest request,@RequestBody SmsTemplateVo vo){
        Long userID = TokenUtil.getUserID(request);
        vo.setUpdateUserId(userID);
        return templateService.updateMessageTemplate(vo);
    }

    /**
     * 短信模板 删除
     * @param request
     * @param id
     * @return
     */
    @GetMapping("/deleteMessageTemplate/{id}")
    @SysTemLog(operModul = "短信模板-删除", operType = "DELETE", operDesc = "短信模板删除功能", modular = "PC")
    public ResultUtil<T> deleteMessageTemplate(HttpServletRequest request, @PathVariable Long id){
        return templateService.deleteMessageTemplate(id);
    }

}
